<template>
<div>
    <div>
    <h3 style="margin-left:20px">新增产品</h3>
    </div>
    <el-form style="width:70%" :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="产品名称" prop="name">
          <el-input class="taskAdd-row-title" placeholder="请输入内容" size="medium" v-model="ruleForm.name" clearable></el-input>
        </el-form-item>
         <el-form-item  label="负责人" style="margin-bottom:0px" prop="masterUserId">
             <selectRoleTwo type='warehouse' selectType='singleChoice' style="width:100%" @selectsuccess='selectsuccess'></selectRoleTwo>
        </el-form-item>
        <el-form-item  label="成员" style="margin-bottom:0px">
             <selectmember type='warehouse'  selectType='multipleChoice' style="width:100%;" @selectsuccess='selectsuccessmamber'></selectmember>
        </el-form-item>
        <el-form-item  label="所属目录" prop="dirId">
              <selectdir style="width:100%" dirType='02'  @dirparenIdtchange='dirparenIdtchange'></selectdir>
        </el-form-item>
        <!-- <div style="display:flex">
            <span style="font-size:14px;color:rgb(96, 98, 102);font-weight:700;width:100px;text-align: end;margin-right:12px">所属标签</span>
            <multipleChoiceTags  :tags="ruleForm.tags" @tagChoose="tagChoose" type="02" style="width: 100%;height: 100%;margin-bottom: 22px;" ></multipleChoiceTags>
          </div> -->
         <el-form-item label='简介'>
              <el-input type="textarea" :rows="5" placeholder="请输入内容" v-model="ruleForm.content"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
            <el-button @click="resetForm">取消</el-button>
        </el-form-item>
    </el-form>
</div>
</template>
<script>
import selectmember from "@/components/screen/selectmember";
import selectdir from '@/components/projectComponents/selectdir'
import quillEditor from '@/components/quillEditor/index'
import multipleChoiceTags from '@/components/select/multipleChoiceTags'
import selectRoleTwo from '@/components/screen/selectRoleTwo'
import {save} from '@/api/prod'
import utils from'@/utils/utils'
 export default({
     name:'produceAdd',
     components: {
        selectmember,
       quillEditor,
       selectRoleTwo,
       selectdir,
       multipleChoiceTags
     },
     data () {
         return {
             ruleForm:{
                 name:"",
                 masterUserId:"",
                 dirId:"",
                 content:"",
                 status:'00',
                //  tags:[],
                 userList:[]
             },
             rules: {
                 name: [
                     { required: true, message: '请输入活动名称', trigger: 'blur' },
                     ],
                 masterUserId: [
                     { required: true, message: '请选择负责人', trigger: 'blur' },
                     ],
                 dirId: [
                     { required: true, message: '请选择目录', trigger: 'blur' },
                     ],
            },
         }
     },
     methods: {
        selectsuccessmamber(data){
             if(!utils.isNull(data)){
                 let userArrat=data.split(",")
                 userArrat.forEach(item=>{ let uers={'userId':item};this.ruleForm.userList.push(uers)})
             }
         },
        // tagChoose(data){
        //     console.log(data);
        //     this.ruleForm.tags=data
        // },
         dirparenIdtchange(data){
              this.ruleForm.dirId=data
         },
         selectsuccess(data){
             this.ruleForm.masterUserId=data[0].userId
         },
         resetForm(){
            this.$emit('resetForm','warehouse','代码仓库')
         },
         submitForm(ruleForm){
           this.$refs[ruleForm].validate((valid) => {
          if (valid) {
                      save(this.ruleForm).then(res=>{
             this.$store.dispatch('tagsView/delView', this.$route).then(({ visitedViews }) => {
                this.$router.push({
                    path:"/produce/index"
                })
              })// 关闭当前tab回到列表
             })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
  
         },
         resetForm(){
            this.$store.dispatch('tagsView/delView', this.$route).then(({ visitedViews }) => {
                this.$router.push({
                    path:"/produce/index"
                })
              })// 关闭当前tab回到列表
         },
     }
 })
</script>
 <style scoped>
 .avatar{
     border-radius: 50%;
     width: 30px;
 }
 .milepostselect{
     display: flex;
     align-items: center;
     margin-bottom: 20px;
     justify-content: space-between;
 }
 .milepostselect_div{
      display: flex;
     align-items: center;
 }
 .milepstdate{
     display: flex;
     width: 100%;
 }
</style>
